package com.demo.webservice.controller;

import com.alibaba.fastjson.JSON;
import com.bootlever.framework.zookeeper.templates.ZookeeperTemplate;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ZookeeperController {

    @Autowired
    private ZookeeperTemplate zookeeperTemplate;

    private static final Logger logger = LoggerFactory.getLogger(ZookeeperController.class);

    @RequestMapping(value = "/createNodeCache")
    public String createNodeCache() throws Exception {
        NodeCache nodeCache  = zookeeperTemplate.createNodeCache("/boot");
        logger.info(JSON.toJSONString(nodeCache));
        return "success";
    }

    @RequestMapping(value = "/createNode")
    public String createNode() throws Exception {
        zookeeperTemplate.createPath("/boot","abc");
        logger.info("创建Node成功");
        return "success";
    }


}
